package helloworld.admin.action.news;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import helloworld.admin.assembler.news.NewsDetailAssembler;
import helloworld.admin.bean.NewsAdminBean;
import helloworld.admin.form.news.NewsForm;
import helloworld.delegate.news.NewsDelegate;
import helloworld.example.util.BaseAction;
import helloworld.example.util.BaseActionForm;
		
/**
 * NewsAction handles all form submission requests for NewsForm.
 * 
 * @author TUYEN-DM
 * @version $Revision: $ $Date:2009/05/25 $
 */
public class NewsCreateAction extends BaseAction {

	public ActionForward process(ActionMapping mapping, BaseActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		request.setCharacterEncoding("UTF-8");
		//response.setCharacterEncoding("UTF-8");

		ActionForward nextPage = mapping.findForward("gotoSearchPage");
		NewsForm newsForm = (NewsForm) form;
		String strAction = request.getParameter("submitAction");

		if (strAction.equals("save")) {
			
			NewsDelegate delegate = new NewsDelegate();
			NewsAdminBean obj = NewsDetailAssembler.createNewsDetail(newsForm);

			if (newsForm.getNewsID() == 0) {
				delegate.createNews(obj);
			} else {
				delegate.updateNews(obj);
			}

		}

		if (strAction.equals("cancel")) {
			System.out.println("Cancel Operation Performed");
		}

		return nextPage;
	}

}